package com.example.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;

import com.example.adapter.MyAdapter.Info;
import com.example.juyixia.R;
import com.exanple.data.ChatMsgEntity;

public class ChatMsgViewAdapter extends BaseAdapter {
	
	public static interface IMsgViewType
	{
		int IMVT_COM_MSG = 0;
		int IMVT_TO_MSG = 1;
	}
	private static String currentusername;
    private List<ChatMsgEntity> data;

    @SuppressWarnings("unused")
	private Context ctx;
    
    private LayoutInflater mInflater;

    public ChatMsgViewAdapter(Context context, List<ChatMsgEntity> data,String currentusername) {
        ctx = context;
        this.data = data;
        ChatMsgViewAdapter.currentusername=currentusername;
        mInflater = LayoutInflater.from(context);
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return data.get(position);
    }
    public long getItemId(int position) {
        return position;
    }
    


	public int getItemViewType(int position) {
		
	 	ChatMsgEntity entity = data.get(position);
		return position;
	 	
	 	
	 	
	}
	
	
    public View getView(int position, View convertView, ViewGroup parent) {
    	 Info info = new Info();
    	 if(data.get(position).getSendname().equals(currentusername)){
    		convertView = mInflater.inflate(R.layout.chatting_item_msg_text_right, null);    		 
    	 }else{
    		 convertView = mInflater.inflate(R.layout.chatting_item_msg_text_left, null);
    	 } 
    	 info.tvContent=(TextView) convertView
             .findViewById(R.id.tv_chatcontent);
    	 info.tvUserName=(TextView) convertView
    	     .findViewById(R.id.tv_username);
    	 info.tvSendTime=(TextView) convertView
        	     .findViewById(R.id.tv_sendtime);
	       
    	 info.tvContent.setText(data.get(position).getMesscontent());
    	 info.tvUserName.setText(data.get(position).getSendname());
    	 info.tvSendTime.setText(data.get(position).getSendtime());
	        
    	
	    return convertView;
    }
    

    static class Info { 
        public TextView tvSendTime;
        public TextView tvUserName;
        public TextView tvContent;      
    }
}
